home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
14389
/
14389.xpi
/
chrome
/
content
/
imgurSearch.js
next >
Wrap
Text File
|
2010-01-25
|
2KB
|
63 lines
if(!com) var com = {};
if(!com.imgur) com.imgur = {};
if(!com.imgur.imgur_fox) com.imgur.imgur_fox = {};
com.imgur.imgur_fox = {
imgur_URL: "http://imgur.com",
targetURL: '',
showImageContext: function() {
var imgur_fox = com.imgur.imgur_fox;
document.getElementById("context-imgur-search").hidden = true;
if(gContextMenu.onImage) {
imgur_fox.targetURL = gContextMenu.mediaURL;
// For versions of Firefox < 3.1
if(!imgur_fox.targetURL) {
imgur_fox.targetURL = gContextMenu.imageURL;
}
document.getElementById("context-imgur-search").hidden = false;
}
},
showImageInit: function() {
var menu = document.getElementById("contentAreaContextMenu");
menu.addEventListener("popupshowing", com.imgur.imgur_fox.showImageContext, false);
},
loadxml: function (location) {
xhttp=new XMLHttpRequest();
xhttp.open("GET",location,false);
xhttp.send(null);
xmlDoc=xhttp.responseXML;
var new_image_url = xmlDoc.getElementsByTagName("original_image")[0].childNodes[0].nodeValue;
var full_url = xmlDoc.getElementsByTagName("imgur_page")[0].childNodes[0].nodeValue;
//open new tab and when finished loading copy url to clipboard
var newTab = gBrowser.getBrowserForTab(gBrowser.addTab(full_url));
const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
gClipboardHelper.copyString(new_image_url);
},
imgurSearch: function() {
var imgur_fox = com.imgur.imgur_fox;
var api_key = 'e1eec71d1a2ac1ad84fd93e301b1ed6c';
var uploadURL = 'http://imgur.com/api/upload.xml';
if(!imgur_fox.targetURL) return;
var location = uploadURL + '?key=' + encodeURIComponent(api_key) + '&image=' + encodeURIComponent(imgur_fox.targetURL);
imgur_fox.loadxml(location);
imgur_fox.targetURL = ''; // Reset
}
}
window.addEventListener("load", com.imgur.imgur_fox.showImageInit, false);